/**   
 * @Title: UsersService.java
 * @Package com.wx
 * @Description: 
 * @author wangxiao
 * @date 2017年11月7日 下午2:24:31
 */
package com.wx.service;

import java.util.List;

import com.jfinal.plugin.activerecord.Db;
import com.wx.model.User;
import com.wx.model.WxAddInfo;

/**   
 * @ClassName: UsersService
 * @Description: 
 * @author wangxiao
 * @date 2017年11月7日 下午2:24:31
 */
public class UserAddService {
	public static final UserAddService me = new UserAddService();
	private final WxAddInfo wxAddDao = new WxAddInfo().dao();
	
	public List<WxAddInfo> getAllAddInfoByUserId(int userId){
		List<WxAddInfo> wxList = wxAddDao.find("select * from wx_add_info w where w.user_id = ? and w.type = 1", userId);
		return wxList;
	}
	
	public WxAddInfo getWxAddInfoById(int id){
		WxAddInfo wx = wxAddDao.findById(id);
		return wx;
	}
	public void setDefaultAdd(int id,int userid){
		Db.update("update wx_add_info d set d.isdefault = 0 where d.user_id=? and d.id<>? and d.type = '1'", userid,id);
		Db.update("update wx_add_info d set d.isdefault = 1 where  d.id=?", id);
	}
	public void setDefaultSendAdd(WxAddInfo wx,User user){
		Db.update("update wx_add_info d set d.isdefault = 0 where d.user_id=? and d.type ='2'", user.getId());
		wx.save();
	}
	public WxAddInfo getUserDefaultSendAdd(int uesrid){
		WxAddInfo wx = wxAddDao.findFirst("select * from wx_add_info d where d.user_id=? and d.type = 2 and d.isdefault = 1", uesrid);
		return wx;
	}
	public WxAddInfo getUserDefaultReceiveAdd(int uesrid){
		WxAddInfo wx = wxAddDao.findFirst("select * from wx_add_info d where d.user_id=? and d.type = 1 and d.isdefault = 1", uesrid);
		return wx;
	}
}
